home *** CD-ROM | disk | FTP | other *** search
- Path: bh.marintek.sintef.no!phi
- From: phi@bh.marintek.sintef.no (Per Henning Isaksen)
- Newsgroups: comp.lang.c
- Subject: typedefs for functions??
- Date: 7 Feb 1996 13:02:56 GMT
- Organization: MARINTEK, the SINTEF Group
- Message-ID: <4fa7u0$516@stork.runit.sintef.no>
- NNTP-Posting-Host: bh.marintek.sintef.no
- X-Newsreader: TIN [version 1.2 PL2]
-
-
-
- The following code works as intended, but I would like to
- change its 'looks'.
-
- 1
- 2 typedef void (*ActionFunction)(char* g);
- 3
- 4 void a(char* b, ActionFunction g) {
- 5 ActionFunction p=g;
- 6 (*p)(b);
- 7 return;
- 8 }
- 9 void aa(char* g) { /* an ActionFunction */
- 10 printf("..%s..\n", g);
- 11 return;
- 12 }
- 13
- 14
- 15 void main() {
- 16 a("adf", aa);
- 17 }
-
- Purpose: Inside a Motif GUI, I want to pass a function that
- can perform some action, so I have the typdef in line 2 to
- define ActionFunction.
-
- I would like to change line 9 to:
- 9 ActionFunction aa(char* g) {
- But this causes a warning on line 16 (but it executes correctly)
- warning 604: Pointers are not assignment-compatible.
- warning 563: Argument #2 is not the correct type.
-
- Of course, I could use a cast, but I wouldn't like it.
-
- Anyone who can teach me the trick?
-
- I want to state the function
- type (via typdefs) both in the parameter list and for the declaration
- of the function itself. (Why? I have lots of functions and I want want
- to mark those that are ActionFunction as such - because some change must
- be done to all functions of this type, but not to other function of
- similar type (i.e. void (char*) in the example)). Obviously, I could
- use a comment, but any error that can be caught by the compiler is
- an error I can forget.
-
-
-
- Per Henning
-
-
-
-
-